/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.business.repository;

import me.zhengjie.business.domain.PricCostDetl;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://el-admin.vip
* @author xiahongbo
* @date 2025-01-12
**/
public interface PricCostDetlRepository extends JpaRepository<PricCostDetl, String>, JpaSpecificationExecutor<PricCostDetl> {


    /**
     * 查询本地费用信息
     * @return /
     */
    @Query(value = "select count(*) zl,  " +
            " min(LONGTERM_PLAN_BEGNTIME) ryrq,  " +
            " max(LONGTERM_PLAN_BEGNTIME) cyrq,  " +
            " sum(amt) zfy, " +
            " sum(case when sfsc = '0' then 1 else 0 end) wsc, " +
            " sum(case when sfsc = '1' then 1 else 0 end) ysc, " +
            " (max(LONGTERM_PLAN_BEGNTIME)- min(LONGTERM_PLAN_BEGNTIME)) * 24 * 60  as hlsc" +
            " from PRIC_COST_DETL " +
            " where pric_rgst_ins_id = ?1 ", nativeQuery = true)
    List<Object> queryPricCostDetl(String rgst_ins_id);
}